console.log($event, '$event');
const helper = new Helper(this)
const prefix = helper.getVariable('environmentType');
const stream = StreamServices.getInstance(prefix)

const { dataTransfer } = $event;

window.handleFuse = async (data, promise = () => { }) => {
    const res = await _videoAccess.getFuseByEquipmentInfo(data);
    // 获取播放地址
    const url = stream.getStreamWebRTCPlayUrl();
    if (!res) return;
    promise().then(result => {
        _videoAccess.addPlayer({
            ...res,
            playerType: 'webrtc',
            equipmentName: result.fuseName || '融合预览',
            url
        });
    })
}

if (!dataTransfer?.getData('data:source')) {
    layer.msg('未找到摄像头配置!');
} else {
    const index = $($event.target).closest('.sullivan-grid-item').data('index')
    const widgets = helper.get('三维组件');
    const sullivan = widgets.widgetObj.sullivan;
    const source = JSON.parse(dataTransfer?.getData('data:source'));
    window.spliceSource = source;
    window.spliceSullivan = sullivan;
    window.spliceIndex = index;

    // console.log('monitorSelect: => ', source);
    if (source.children) {
        layer.msg('未找到摄像头配置!');
    } else {
        const oldVideo = sullivan.cameraMap.get(+index);
        window.spliceOldVideo = oldVideo;
        console.log('oldVideo: => ', oldVideo, index, window.videoSpliceIndex);
        if (oldVideo) {
            if (oldVideo.data?.id === source.id) {
                layer.msg('您选中的是同一个视频，请重新选择!');
            } else {
                const modals = this.pageObj.getApiWidgetsByClassName('video-splice-modal');
                modals.forEach(v => v.showWidget());
            }
        } else {
            _videoAccess.addPlayer(source);
        }
    }
    // console.log(source, 'source')
}